package com.lims;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author limaosheng
 * @create 2022-11-18 14:58
 * @desc
 */
public class 入库小脚本 {

    public final static String DB_URL = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
    public final static String DB_USER = "root";
    public final static String DB_PWD = "123456";

    public static void main(String[] args) {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PWD);
            String[] arr = a.split("\n");
            for(String s : arr){
                String[] farr = s.split("，");
                try {
                    String sql = "INSERT INTO `test`.`aaaa` (`id`, `count`) VALUES ("+farr[1].substring(5)+", "+farr[0].substring(3)+");";
                    PreparedStatement ps2 = conn.prepareStatement(sql);
                    int i = ps2.executeUpdate();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println(s);
                }
            }
        } catch (Exception throwables) {
            throwables.printStackTrace();
        } finally {
            closeConn(conn);
        }
    }

    public static void closeConn(Connection conn) {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    static final String a = "人数：14，小区ID：2\n" +
            "人数：2598，小区ID：19";
}
